#!/bin/bash

java_cmd="/usr/bin/java"

stop()
{
    PID=`ps ax | grep sconsumer | grep java | head -1 | awk '{print $1}'`
    if [ -n "$PID" ];then
        kill $PID
        echo "killing ..."
        sleep 1s
        echo "killed $PID"
    fi
}

start()
{
    echo "starting ..."
    nohup ${java_cmd} -jar ./target/sconsumer-1.0-SNAPSHOT.jar > /dev/null 2>&1 &
    PID=`ps ax | grep sconsumer | grep java | head -1 | awk '{print $1}'`
    while [ ! -n "$PID" ]
    do
        PID=`ps ax | grep sconsumer | grep java | head -1 | awk '{print $1}'`
        sleep 1s
    done
    echo "started $PID"
}

stop
start